<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:test="http://xsltut.googlecode.com">
    <test:testCase name="matchTest">
        <test:test name="select">
            <test:input select="/html/body">
                <html>
                    <body version="1.0">
                        <p>Hello, World</p>
                    </body>
                </html>
            </test:input>
            <test:expect>
                <body version="1.0">
                    <p>Hello, World</p>
                </body>
            </test:expect>
        </test:test>
    </test:testCase>
    <test:testCase name="callTest">
        <test:test name="factorial5">
            <test:xslt>
                <xsl:call-template name="factorial">
                    <xsl:with-param name="num" select="5"/>
                </xsl:call-template>
            </test:xslt>
            <test:expect type="number">120</test:expect>
        </test:test>
        <test:test name="factorial0">
            <test:xslt>
                <xsl:call-template name="factorial">
                    <xsl:with-param name="num" select="0"/>
                </xsl:call-template>
            </test:xslt>
            <test:expect type="number">1</test:expect>
        </test:test>
    </test:testCase>
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="*">
        <xsl:copy>
            <xsl:for-each select="@*">
                <xsl:copy/>
            </xsl:for-each>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:template name="factorial">
        <xsl:param name="num"/>
        <xsl:param name="result" select="1"/>
        <xsl:choose>
            <xsl:when test="$num > 0">
                <xsl:call-template name="factorial">
                    <xsl:with-param name="num" select="$num -1"/>
                    <xsl:with-param name="result" select="$result * $num"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$result"/>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
</xsl:stylesheet>
